function [cur,wrapping_size] = curvelet_limitedAngle_fixedFading( imSize,radial,angular, pieces, inner_angl, outer_angl)
%The angular region used to fade the tile from 1 to zero is fixed in the
%angular sector between the inner and the outer angle. Hereby the inner
%angular tile is split into a given number of pieces. This is used to
%define the single wedges.
%
%author: Sebastian Schmelcher; version: 2012-04-24



identifier=['limitedAngle_fixedFading_' num2str(pieces) '_' num2str(inner_angl) '_' num2str(outer_angl)];
map=get_indexStruct(identifier,imSize);

num_radial=length(map);

n=imSize(1);
m=imSize(2);

origin=get_origin([n,m]);




if(radial==0)
    cur=[0.928241517645832,1,0.928241517645832;1,1,1;0.928241517645832,1,0.928241517645832];
    point=[origin(1)-1 origin(2)-1; origin(1)+1 origin(2)+1 ];
    cur={cur,point,[0,0]};
    wrapping_size=[3, 3];
    return;
end

if(radial>num_radial)
    return;
end

if(angular>map(radial))
    return;
end


curvelet_width=(inner_angl+outer_angl)/map(radial);
curvelet_dir=-(inner_angl+outer_angl)/4+(angular-.5)*curvelet_width;
if(angular>map(radial)/2)
    curvelet_dir=curvelet_dir+180-(inner_angl+outer_angl)/2;
end


%1-f verhaelt sich zu 1 wie (oa-ia)/2 zu curv_width
f=1-(outer_angl-inner_angl)/(2*curvelet_width);
if(f<0)
    error('somethings wrong with the angles! Try a larger inner angle, a smaller outer angle or reduce the pieces.')
end




curvelet_dir=pi*curvelet_dir/180;
curvelet_dir=angle(exp(1i*curvelet_dir)); %modulo
curvelet_width=pi*curvelet_width/180;
curvelet_supp_width=curvelet_width+(outer_angl-inner_angl)*pi/360; 

[point,shift,wrapping_size]=get_Curvelet_point_shift(radial,curvelet_dir,curvelet_supp_width,origin,n,m,num_radial);


%%%%%%%%% faster %%%%%%%%%%%%
[X,Y]=meshgrid(point(3)-origin(1):point(4)-origin(1),point(1)-origin(2):point(2)-origin(2));
[theta,rad]=cart2pol(X,Y);
rad=(2^(-radial)).*rad;
theta=angle(exp(1i*(theta-curvelet_dir)))/curvelet_width*2;
if(radial==num_radial)
    cur2=lastRadialWindow(rad).*angularWindow(theta,f); %no upper limit
else
    cur2=radialWindow(rad).*angularWindow(theta,f);
end

cur={cur2,point,shift};
   

% -------------------------------------------------------------------------
function x = lastRadialWindow(r)
%no upper limit
rSize=size(r);

x= (r>=(5/6));
x=x+cos((5*ones(rSize)-6*r)*(pi/2)).*(r>=(2/3)) .* (r<(5/6));

x=( (r>=(5/6)) .* (r<=(4/3)) );
x=x+cos((5*ones(rSize)-6*r)*(pi/2)).*(r>=(2/3)) .* (r<(5/6));
x=x+cos((3*r-4*ones(rSize))*(pi/2)).*(r>(4/3)) .* (r<=(5/3));

% -------------------------------------------------------------------------

function x = angularWindow(t,f)
t=abs(t);
tSize=size(t);


x=(t<=f);
x=x+((t<=2-f).*(t>f) .* cos(  1/(2-2*f)*(t-f*ones(tSize))*(pi/2) ));



% -------------------------------------------------------------------------
function x = radialWindow(r)
rSize=size(r);

x=( (r>=(5/6)) .* (r<=(4/3)) );
x=x+cos((5*ones(rSize)-6*r)*(pi/2)).*(r>=(2/3)) .* (r<(5/6));
x=x+cos((3*r-4*ones(rSize))*(pi/2)).*(r>(4/3)) .* (r<=(5/3));



